import threading
import time


class FooBar:
    def __init__(self, n):
        self.n = n
        self.flag = 1

    def foo(self, printFoo: 'Callable[[], None]') -> None:
        for i in range(self.n):
            while self.flag != 1:
                time.sleep(0.0001)
            printFoo()
            self.flag = 2

    def bar(self, printBar: 'Callable[[], None]') -> None:
        for i in range(self.n):
            while self.flag != 2:
                time.sleep(0.0001)
            printBar()
            self.flag = 1


def printFoo():
    print("foo", end="")


def printBar():
    print("bar", end="")


if __name__ == '__main__':
    tool = FooBar(1)
    threading.Thread(target=tool.foo, args=[printFoo]).run()
    threading.Thread(target=tool.bar, args=[printBar]).run()
